package com.woniu40.petai_user.service;

import com.woniu40.petai_user.entity.*;
import com.woniu40.petai_user.mapper.CartMapper;
import com.woniu40.petai_user.mapper.GoodsMapper;
import com.woniu40.petai_user.mapper.OrderItemMapper;
import com.woniu40.petai_user.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class OrderService {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderItemMapper orderItemMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    CartMapper cartMapper;

    public List<Order> findOrderAll(Integer userId){
        List<Order> orders = orderMapper.selectOrderAll(userId);
        return orders;
    }

    public Order findOrderById(Integer orderId){
        Order order = orderMapper.selectByPrimaryKey(orderId);
        return order;
    }

    public Order findOrderByNum(String orderNum){
        Order order = orderMapper.selectByOrderNum(orderNum);
        return order;
    }

    public int modifyOrder(Order order){
        orderMapper.updateByPrimaryKey(order);
        return 1;
    }

    public int removeProduct(String orderNum){
        return orderMapper.deleteBuyProduct(orderNum);
    }
}
